"""StaffLog SetUp - Predesys service
@version: 0.1
@license: GPL 3.0 (see "license" file)
@author: Jose A. Jimenez <jajimc@gmail.com>, Miguel Centeno <miguelcent@gmail.com>"""

import sys
sys.dont_write_bytecode = True
import os
DIR = os.path.abspath(os.path.dirname(os.path.realpath(__file__)))
sys.path.append(os.path.join(DIR, "../core"))
import data

### SERVICE TEMPLATE ###
def get_service_id():
    return "stafflog-setup"
    
def get_version():
    return "0.1"
    
def get_service_name():
    return "StaffLog SetUp"
    
def get_author():
    return "Jose A. Jimenez <jajimc@gmail.com>, Miguel Centeno <miguelcent@gmail.com>"
    
def run(userId, args):
    success = False
    
    try:        
        distanceEyeEyeHor = args[0]
        distanceEyeNoseVer = args[1]
        distanceEyeNoseHor = args[2]
        distanceNoseMouthVer = args[3]
        
        record_distances(userId, distanceEyeEyeHor, distanceEyeNoseVer, distanceEyeNoseHor, distanceNoseMouthVer)
        success = True
    except:
        pass
            
    return success
    
def record_distances(userId, distanceEyeEyeHor, distanceEyeNoseVer, distanceEyeNoseHor, distanceNoseMouthVer):
    try:
        dbConnection = data.open_connection()
        
        statement = "insert into serv_stafflog_distances values ('%s', %s, %s, %s, %s);" % (userId, distanceEyeEyeHor, distanceEyeNoseVer, distanceEyeNoseHor, distanceNoseMouthVer)
        result = data.execute(dbConnection, statement)
        result.close()
        
        data.close_connection(dbConnection)
    except:
        raise
